package com.kx.yooli.kx.wechat.config.handler;

import com.kx.yooli.kx.wechat.entity.disrutor.MessageModel;
import com.lmax.disruptor.EventHandler;
import com.lmax.disruptor.Sequence;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author john_sqwen-childe.wen
 * @date 2024/3/28
 * @PROJECT_NAME wechat
 * @description create MessageEventHandler by john_sqwen
 * and EventHandler value is
 */
public class MessageEventHandler implements EventHandler<MessageModel> {
    private final Logger log = LoggerFactory.getLogger(MessageEventHandler.class);
    @Override
    public void onEvent(MessageModel messageModel, long l, boolean b) throws Exception {

        try{
            //Stopping 1000ms here is to confirm that the consumption message is asynchronous
            Thread.sleep(1000);
            log.info("Consumer processing message begins");
            if (messageModel != null) {
                log.info("Consumer processing message value is ：{}",messageModel);
            }
        }catch (Exception e){
            log.info("Consumer processing message fail");
            e.printStackTrace();
        }
        log.info("Consumer processing message is end");
    }

    @Override
    public void onBatchStart(long batchSize, long queueDepth) {
        EventHandler.super.onBatchStart(batchSize, queueDepth);
    }

    @Override
    public void onStart() {
        EventHandler.super.onStart();
    }

    @Override
    public void onShutdown() {
        EventHandler.super.onShutdown();
    }

    @Override
    public void onTimeout(long sequence) throws Exception {
        EventHandler.super.onTimeout(sequence);
    }

    @Override
    public void setSequenceCallback(Sequence sequenceCallback) {
        EventHandler.super.setSequenceCallback(sequenceCallback);
    }
}
